package domain;

public class Car {
	
	public Car(Segment startPos, String id) {
		this.position = startPos;
		startPos.setCar(this);
		this.id = id;
	}
	
	/* *** positie *** */
	
	public Segment getPosition() {
		return position;
	}
	
	private Segment position;
	
	public void move(Segment newPosition) {
		if(newPosition == null) throw new IllegalArgumentException("Tried to move car to null");
		if(newPosition.getCar() != null) throw new IllegalArgumentException("Tried to crash the car");
		if(this.position != null) this.position.removeCar();
		this.position = newPosition;
		newPosition.setCar(this);
	}
	
	//verwijdert auto van segment
	public void disappear() {
		Segment oldPos = position;
		position = null;
		oldPos.setCar(null);
	}
	
	
	
	@Override
	public String toString() {
		return id;
	}
	
	/* *** Id *** */
	
	//uniek label per auto
	public String getId() {
		return id;
	}
	
	private final String id;

}
